package org.fearsomej.list.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.fearsomej.list.domain.DataUser;
import org.fearsomej.list.domain.Task;

import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.client.http.AuthSubUtil;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

public class GoogleCalendar {
	
	
	/**
	 * exmaple from calendar template project
	 */
	public List<CalendarEntry> getAllCalendars() {
		List<CalendarEntry> entries = null;
		try {

			// Create a new Calendar service
			CalendarService myService = new CalendarService("My Application");
			myService.setUserCredentials("", "");

			// Get a list of all entries
			URL metafeedUrl = new URL(
					"http://www.google.com/calendar/feeds/default/allcalendars/full");
			System.out.println("Getting Calendar entries...\n");
			CalendarFeed resultFeed = myService.getFeed(metafeedUrl,
					CalendarFeed.class);
			entries = resultFeed.getEntries();			
		} catch (AuthenticationException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return entries;
	}

	

}
